package com.budwk.app.sqfwV2.component;

import cn.hutool.core.util.IdcardUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * 创业实体入户公共服务类
 */

@Slf4j
public class EntrepreneurShipHouseComponent {

    public static final String NO_SUBMIT = "未提供";

    public static String formatStr(String str) {
        return StringUtils.isNotEmpty(str) ? str : NO_SUBMIT;
    }


    /**
     * 计算年龄
     * @param idcard
     * @param age
     * @return
     */
    public static Integer calAge(String idcard, Integer age) {
        try {
            if (age != null) {
                return age;
            }
            if (StringUtils.isNotEmpty(idcard)) {
                return IdcardUtil.getAgeByIdCard(idcard);
            }
        } catch (Exception e) {
            log.error("calAge err: ", e);
        }
        return null;
    }

    /**
     * 计算性别
     * @param idcard
     * @param gender
     * @return
     */
    public static Integer calGender(String idcard, Integer gender) {
        try {
            if (gender != null) {
                return gender;
            }
            if (StringUtils.isNotEmpty(idcard)) {
                return IdcardUtil.getGenderByIdCard(idcard);
            }
        } catch (Exception e) {
            log.error("calGender err: ", e);
        }
        return null;
    }
}
